package com.csdj.music.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csdj.music.vo.RankList;
import com.csdj.music.service.RankListService;
import com.csdj.music.mapper.RankListMapper;
import com.csdj.music.vo.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author XuTao
* @description 针对表【rank_list】的数据库操作Service实现
* @createDate 2023-03-13 15:53:22
*/
@Service
public class RankListServiceImpl extends ServiceImpl<RankListMapper, RankList>
    implements RankListService{
    @Autowired(required = false)
    private RankListMapper rankListMapper;
    @Override
    public RespBean insert(RankList rankList) {
        if (rankListMapper.insert(rankList)>0){
            return RespBean.success("200","评分成功");
        }
        return RespBean.error("500","评分失败");
    }

    @Override
    public int selectScoreSum(Integer songListId) {
        return rankListMapper.selectScoreSum(songListId);
    }

    @Override
    public int selectRankNum(Integer songListId) {
        return rankListMapper.selectRankNum(songListId);
    }

    @Override
    public int rankOfsongListId(Integer songListId) {
        int rankNum=rankListMapper.selectRankNum(songListId);
        if (rankNum==0){
            return 5;
        }
        return rankListMapper.selectScoreSum(songListId)/rankNum;
    }
}




